package com.cskaoyan.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * @author wenkaikai,已弃用
 * @since 2022/08/13 22:31
 */
//@Component
public class IntegerArrayToString implements Converter<Integer[], String> {

    @Override
    public String convert(Integer[] source) {
        if (source == null) {
            return null;
        }
        if (source.length == 0) {
            return "[]";
        }
        StringBuffer stringBuffer = new StringBuffer("[");
        for (Integer integer : source) {
            stringBuffer.append(integer + ",");
        }
        int index = stringBuffer.lastIndexOf(",");
        stringBuffer.replace(index, index + 1, "]");
        return stringBuffer.toString();
    }
}